package org.stragma.symbian.aterms;

import java.util.*;
import aterm.*;

public class TermMapper {

	private Map<Integer, ATerm> termMap;
	
	/**
	 * Constructor
	 */
	public TermMapper() {
		this.termMap = new HashMap<Integer, ATerm>();
	}
	
	/**
	 * Adds the term to the map if it is not already in the map
	 * @param term
	 */
	public void setMap(ATerm term) {
		if (!this.isMapped(term)) {
			if (term instanceof ATermAppl) {
				//System.out.println(this.termMap.size() + ": Adding the term " + ((ATermAppl)term).getName() + " to map");
			}
			
			if (term instanceof ATermList) {
				//System.out.println(this.termMap.size() + ": Adding list with child count " + ((ATermList)term).getChildCount() + " to map");
			}
			
			this.termMap.put(term.getUniqueIdentifier(), term);
		}
	}
	
	/**
	 * Returns a value indicating the type has been mapped
	 * @param term
	 * @return
	 */
	public boolean isMapped(ATerm term) {		
		return this.termMap.containsKey(term.getUniqueIdentifier());
	}
}
